//
// Created by tsl on 2021/6/23.
//

#include "frame2video.h"
#include <string>
#include <vector>

void free_mem(char *buff_ptr){
    if(buff_ptr!=NULL){
        free(buff_ptr);
        buff_ptr=NULL;
    }
}

void fream2video(char *frame_path,char *video_path_name){
    std::vector<cv::String>file_names;
    std::vector<cv::String>::iterator iterator;

    cv::VideoWriter videoWriter ;

    videoWriter.open(video_path_name,cv::VideoWriter::fourcc('M', 'J', 'P', 'E') ,5.0,cv::Size(960,540), true);
    cv::glob(frame_path,file_names);
    cv::Mat frame;
    char *buff_ptr = (char*) malloc(102400);
    for(iterator=file_names.begin();iterator!=file_names.end();iterator++ ){
        sprintf(buff_ptr,"%s",iterator->c_str());
        puts(buff_ptr);
        frame = cv::imread(buff_ptr);
        cv::imshow("frame",frame);
        cv::waitKey(1);
        videoWriter.write(frame);
    }
    free_mem(buff_ptr);
}